﻿using AutoMapper;
using CollegeSim.Domain.DTO;

namespace CollegeSim.Persistence
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 5/13/2014

    /// <summary>
    /// Creates type maps for CollegeSim persistence.
    /// </summary>
    public static class PersistenceMapConfig
    {
        /// <summary>
        /// Create type maps.
        /// </summary>
        public static void Intialize()
        {
            // Course
            Mapper.CreateMap<Course, CourseDTO>();
            Mapper.CreateMap<CourseDTO, Course>();
            
            // Semester
            Mapper.CreateMap<Semester, SemesterDTO>();
            Mapper.CreateMap<SemesterDTO, Semester>();

            // SchoolYear
            Mapper.CreateMap<SchoolYear, SchoolYearDTO>();
            Mapper.CreateMap<SchoolYearDTO, SchoolYear>();

            // Session
            Mapper.CreateMap<Session, SessionDTO>();
            Mapper.CreateMap<SessionDTO, Session>();

            // Person
            Mapper.CreateMap<Person, PersonDTO>();
            Mapper.CreateMap<PersonDTO, Person>();

            // Instructor
            Mapper.CreateMap<Instructor, InstructorDTO>()
                .ForMember(dto => dto.FirstName, opt => opt.MapFrom(i => i.Person.FirstName))
                .ForMember(dto => dto.LastName, opt => opt.MapFrom(i => i.Person.LastName))
                .ForMember(dto => dto.PhoneNumber, opt => opt.MapFrom(i => i.Person.PhoneNumber))
                .ForMember(dto => dto.Email, opt => opt.MapFrom(i => i.Person.Email));
            Mapper.CreateMap<InstructorDTO, Instructor>();

            // Student
            Mapper.CreateMap<Student, StudentDTO>()
                .ForMember(dto => dto.FirstName, opt => opt.MapFrom(s => s.Person.FirstName))
                .ForMember(dto => dto.LastName, opt => opt.MapFrom(s => s.Person.LastName))
                .ForMember(dto => dto.PhoneNumber, opt => opt.MapFrom(s => s.Person.PhoneNumber))
                .ForMember(dto => dto.Email, opt => opt.MapFrom(s => s.Person.Email));
            Mapper.CreateMap<StudentDTO, Student>();
        }
    }
}
